//两数之和
import java.util.HashMap;
import java.util.Map;

class Solution {
    public int[] twoSum(int[] nums, int target) {
        //使用hash表
        Map<Integer, Integer> hash = new HashMap<>();
        for(int i = 0;i < nums.length;i++){
            if(hash.containsKey(target - nums[i])){
                return new int[]{i,hash.get(target - nums[i])};
            }
            hash.put(nums[i],i);
        }
        return new int[0];


        //暴力枚举
        /*
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[] { i, j };
                }
            }
        }
        return new int[0];
        */
    }
}
